package tests.context;

import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.context.annotation.Scope;
import qq2564874169.tuaotuao.fx.context.BeanContext;

@Configuration
public class ModelBean {
    @Bean
    @Primary
    @Scope(BeanContext.SCOPE_SINGLETON)
    public Model getModel1_1() {
        Model m = new Model();
        m.id = "1";
        return m;
    }

    @Bean("model1_2")
    @Scope(BeanContext.SCOPE_SINGLETON)
    public Model getModel1_2() {
        Model m = new Model();
        m.id = "2";
        return m;
    }

    @Bean
    @Primary
    @Scope(BeanContext.SCOPE_PROTOTYPE)
    public Model2 getModel2_1(Model model) {
        Model2 m = new Model2(model);
        m.id = 1;
        return m;
    }

    @Bean("model2_2")
    @Scope(BeanContext.SCOPE_PROTOTYPE)
    public Model2 getModel2_2(ApplicationContext context) {
        Model2 m = new Model2(context.getBean("model1_2", Model.class));
        m.id = 2;
        return m;
    }

    @Bean
    @Scope(BeanContext.SCOPE_CONTEXT)
    public Model4 getModel4() {
        return new Model4();
    }
}
